import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
} from 'typeorm';
import { CommonEntity } from 'src/common/entity/index.entity';
import { RoleEntity } from '../../role/entities/role.entity';
import { BlogEntity } from '../../blog/entities/blog.entity';
import { ApiProperty } from '@nestjs/swagger';

@Entity('user', {})
export class UserEntity extends CommonEntity {
  @ApiProperty({ default: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' })
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty({ default: '小明' })
  @Column('varchar', { length: 50, comment: '用户名' })
  username: string;

  @Column('varchar', { length: 50, comment: '密码', select: false })
  password: string;

  @ApiProperty({ default: 'email@email.com' })
  @Column('varchar', { length: 50, nullable: true, comment: '邮箱' })
  email: string | null;

  @ApiProperty({ default: 188888888888 })
  @Column('bigint', { nullable: true, comment: '电话' })
  phone: number | null;

  @Column('varchar', {
    length: 200,
    nullable: true,
    comment: 'token值',
    select: false,
  })
  token: string | null;

  @Column('varchar', { length: 50, comment: '盐', select: false })
  salt: string;

  @ApiProperty({ type: () => RoleEntity })
  @ManyToOne(() => RoleEntity, (role) => role.users)
  role: RoleEntity;

  @OneToMany(() => BlogEntity, (blog) => blog.user)
  blogs: BlogEntity[];
}
